import ReactDOM, { render } from 'react-dom';
import React, { useEffect, useState } from 'react';
// import 'babel-polyfill';
import { ConfigProvider } from 'antd';
import zh_CN from 'antd/lib/locale-provider/zh_CN';
import 'braft-editor/dist/index.css';
import 'core-js';
import { createRoot } from 'react-dom/client';
import { createBrowserRouter, RouterProvider, Route, Link, Routes, BrowserRouter, HashRouter, Outlet } from 'react-router-dom';
// import "core-js/modules/es.array.iterator";

import { LazyLoad, KeepAlive, CProps } from '@/components/Index';

import { RouteField, routes } from '@/router/index';
import { getHash } from '@/utils/public';
import { setStore, connect } from '@/state/Connect';

import '@/index.global.less';
import './index.less';

import '@/utils/adaptation';

// 热更新
if (module?.hot) {
  module.hot.accept();
}

// const router = createBrowserRouter(routes);

const routerRender = (list: RouteField[]) => {
  return list.map((item) => {
    if (item.path === '/') {
      return (
        <Route key={item.path} path={item.path} element={<Outlet />}>
          {item.children?.length > 0 ? routerRender(item.children) : null}
        </Route>
      );
    }

    return (
      <Route key={item.path} path={item.path} element={<item.component />}>
        {item.children?.length > 0 ? routerRender(item.children) : null}
      </Route>
    );
  });
};

const App = () => {
  return <Routes>{routerRender(routes)}</Routes>;
};

createRoot(document.getElementById('root')!).render(
  <HashRouter>
    <React.StrictMode>
      <App />
    </React.StrictMode>
  </HashRouter>
);
